package com.ruoyi.heytalk.controller.system;

import com.ruoyi.common.constant.heytalk.CommonConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.heytalk.ImFriend;
import com.ruoyi.common.core.domain.heytalk.dto.FriendSetBlackDTO;
import com.ruoyi.common.core.domain.heytalk.dto.FriendSetMomentAuthDTO;
import com.ruoyi.common.core.domain.heytalk.dto.FriendSetStarDTO;
import com.ruoyi.common.core.domain.heytalk.vo.MailFriendListVO;
import com.ruoyi.common.core.domain.heytalk.vo.UserDetailVO;
import com.ruoyi.heytalk.service.IImFriendService;
import com.ruoyi.heytalk.service.IImUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 用户数据请求控制器
 * @author zhusy
 * @since 2021/11/10
 */
@Api(value = "用户数据请求控制层", tags = {"用户数据请求控制层"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping(CommonConstants.HEY_TALK)
public class UserController extends BaseController {

    private final IImUserService userService;

    private final IImFriendService friendService;

    @ApiOperation("查看用户资料")
    @GetMapping("/friend/read/{userId}")
    public AjaxResult<UserDetailVO> getUserInfo(@NotBlank(message = "用户ID不能为空")
                                                @PathVariable("userId") String userId){
        return userService.getUserInfo(userId);
    }

    @ApiOperation("我的通讯录")
    @GetMapping("/friend/list")
    public AjaxResult<List<MailFriendListVO>> friendList() {
        return friendService.friendList();
    }

    @ApiOperation("移入/移除黑名单")
    @PostMapping("/friend/setBlack")
    public AjaxResult<Void> friendSetBlack(@Validated @RequestBody FriendSetBlackDTO friendSetBlackDTO) {
        return friendService.friendSetBlack(friendSetBlackDTO);
    }

    @ApiOperation("设置/取消星标好友")
    @PostMapping("/friend/setStar")
    public AjaxResult<Void> friendSetStar(@Validated @RequestBody FriendSetStarDTO friendSetStarDTO) {
        return friendService.friendSetStar(friendSetStarDTO);
    }

    @ApiOperation("设置朋友圈权限")
    @PostMapping("/friend/setMomentAuth")
    public AjaxResult<Void> friendSetMomentAuth(@Validated @RequestBody FriendSetMomentAuthDTO friendSetMomentAuthDTO) {
        return friendService.friendSetMomentAuth(friendSetMomentAuthDTO);
    }

}
